<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/**
 * Model that handles all security calls to the mongo database
 *
 * @author Anton Foster
 */

class security_model extends CI_Model {
    
    public function __construct()
	{
            parent::__construct();
            // Load the mongo Driver
            $mongo = new MongoClient();
            // select a database
            $this->mongodb = $mongo->areaforum;
            $this->load->helper('url');
            // LOAD LIBRARIES
            $this->load->library(array('encrypt'));
            
        }
    
     public function verifycrud ($page) {
       // funtion to determin the users rights for a page in terms of CRUD 
       
   }   
   
   public function CheckCred( $creds ) {
       // Check login creds
       // $login = array('username' => $user_name, 'passwd' => $user_pass) ;
       $crit = array('username' => $creds['username']  );
        $collection = $this->mongodb->users;
        $result = $collection->findOne($crit);
      //  var_dump($this->encrypt->decode($result['passwd']));
        if ($result['username'] == $creds['username'] && $this->encrypt->decode($result['passwd']) == $creds['passwd'] ) {
            return $result ; 
        //    var_dump($result);
        } else { $return = NULL; }
   }
       
     
   
   public function logout() {
       // funtion to logout the user
       
   }
   
   public function adduser( $userdata ) {
       // funtion to add a user
       
   }
    // connect
                
    
}

?>
